<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

$deviceId = $_GET['deviceId'];
$skillId = $_GET['serviceId'];
$skillLevel =$_GET['skillLevel'];
$action = $_GET['action'];
$temp = DeviceUse::GetByDeviceAndSkill($deviceId, $skillId);

if("add" == $action){
	if( $temp == null ){
		$deviceUse = array();
		$deviceUse['device_id'] = $deviceId;
		$deviceUse['service_id'] = $skillId;
		$deviceUse['skill_level'] = $skillLevel;
		DeviceUse::Create($deviceUse);
		$service = Service::GetById($skillId);
		Output::Json($service['service_name']."(level:".$skillLevel.")", 0);
	}else{
		Output::Json(null, 1);
	}
}else{
	if( $temp == null ){
		Output::Json(null, 1);
	}else{
		DeviceUse::Delete($deviceId, $skillId);
		$service = Service::GetById($skillId);
		Output::Json($service['service_name'], 0);
	}
}
